package com.example.medical.Controller;

import com.example.medical.Bean.Team;
import com.example.medical.Bean.dilixinxi;
import com.example.medical.Mapper.teamMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class TeamController {
    @Autowired
    private teamMapper teamMapper;

    /**
     * 根据请求，返回团队管理界面
     * @return
     */
    @RequestMapping("/team/list")
    public String list(){
        return "team/list";
    }

    /**
     * 接收teamList请求，返回数据库的Team表内的所有内容，格式为json
     * @return
     */
    @GetMapping("teamList")
    @ResponseBody
    public List<Team> getTeamList(){
        return teamMapper.getAll();
    }

    /**
     * 接收insertTeam请求，向Team中插入内容
     * @param ID
     * @param doctorName
     * @param TeamName
     * @param tel
     */
    @PostMapping("insertTeam")
    public void insertTeam(
            @RequestParam String ID,
            @RequestParam String doctorName,
            @RequestParam String TeamName,
            @RequestParam String tel
            ){
        Team team=new Team();
        team.setTel(ID);
        team.setTeamName(TeamName);
        team.setDoctorName(doctorName);
        team.setTel(tel);
        teamMapper.insert(team);
    }

    /**
     * 接收updateTeam请求，根据ID值更新Team内容
     * @param ID
     * @param doctorName
     * @param TeamName
     * @param tel
     */
    @PutMapping("updateTeam")
    public void updateTeam(
            @RequestParam String ID,
            @RequestParam String doctorName,
            @RequestParam String TeamName,
            @RequestParam String tel
            ){
        Team team=new Team();
        team.setTel(ID);
        team.setTeamName(TeamName);
        team.setDoctorName(doctorName);
        team.setTel(tel);
        teamMapper.update(team);
    }
}
